package com.ruoyi.project.module.lck.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;


import com.ruoyi.project.domain.YhAppointment;
import com.ruoyi.project.service.IYhAppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 预约信息Controller
 * 
 * @author ruoyi
 * @date 2023-03-09
 */
@RestController
@RequestMapping("/lck/appointment")
public class LckAppointmentController extends BaseController
{
    @Autowired
    private IYhAppointmentService yhAppointmentService;

    /**
     * 查询预约信息列表
     */
    @RequiresPermissions("lck:appointment:list")
    @GetMapping("/list")
    public TableDataInfo list(YhAppointment yhAppointment)
    {
        startPage();
        List<YhAppointment> list = yhAppointmentService.selectYhAppointmentList(yhAppointment);
        return getDataTable(list);
    }
    /*导入预约信息列表*/
    @RequiresPermissions("lck:appointment:import")
    @Log(title = "预约", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<YhAppointment> util = new ExcelUtil<YhAppointment>(YhAppointment.class);
        List<YhAppointment> mapList = util.importExcel(file.getInputStream());
        String message = yhAppointmentService.importContract(mapList, updateSupport);
        return AjaxResult.success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<YhAppointment> util = new ExcelUtil<YhAppointment>(YhAppointment.class);
        util.importTemplateExcel(response, "导入数据");
    }
    /**
     * 导出预约信息列表
     */
    @RequiresPermissions("lck:appointment:export")
    @Log(title = "预约信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhAppointment yhAppointment)
    {
        List<YhAppointment> list = yhAppointmentService.selectYhAppointmentList(yhAppointment);
        ExcelUtil<YhAppointment> util = new ExcelUtil<YhAppointment>(YhAppointment.class);
        util.exportExcel(response, list, "预约信息数据");
    }

    /**
     * 获取预约信息详细信息
     */
    @RequiresPermissions("lck:appointment:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(yhAppointmentService.selectYhAppointmentById(id));
    }

    /**
     * 新增预约信息
     */
    @RequiresPermissions("lck:appointment:add")
    @Log(title = "预约信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhAppointment yhAppointment)
    {
        return toAjax(yhAppointmentService.insertYhAppointment(yhAppointment));
    }

    /**
     * 修改预约信息
     */
    @RequiresPermissions("lck:appointment:edit")
    @Log(title = "预约信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhAppointment yhAppointment)
    {

        return toAjax(yhAppointmentService.updateYhAppointment(yhAppointment));
    }

    /**
     * 删除预约信息
     */
    @RequiresPermissions("lck:appointment:remove")
    @Log(title = "预约信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhAppointmentService.deleteYhAppointmentByIds(ids));
    }
}
